

<template>
  <div>
    <div v-for="(item, index) in list" :key="index">
      <!-- 活动未结束 -->
      <div
        v-if="item.endtime * 1000 > current_time"
        class="item-box"
        @click="goJoin(item)"
      >
        <div class="img-box" v-if="item.theme_image">
          <img :src="sourceURL + item.theme_image" alt="" />
        </div>
        <div class="img-box" v-else>
          <img src="../assets/images/news-list-img.jpg" alt="" />
        </div>
        <div class="right-box">
          <div class="title">{{ item.title }}</div>
          <div class="time-style">
            活动时间：{{ (item.endtime * 1000) | timeFormat("YYYY-MM-DD") }}
          </div>
          <div class="type-style flexc" v-if="item.act_type == 1">问卷活动</div>
          <div class="type-style flexc" v-if="item.act_type == 2">答题活动</div>
          <div class="btn-style">
            <van-button
              round
              type="info"
              color="#F57373"
              v-if="item.join_status == '0'"
              >未参与</van-button
            >
            <van-button
              round
              type="info"
              color="#FFA32B"
              v-if="item.join_status == 1"
              >已参与</van-button
            >
          </div>
        </div>
      </div>
      <!-- 活动已结束 -->
      <div class="item-box" v-else @click="onFinish(item)">
        <div class="img-box" v-if="item.theme_image">
          <img :src="sourceURL + item.theme_image" alt="" />
        </div>
        <div class="img-box" v-else>
          <img src="../assets/images/news-list-img.jpg" alt="" />
        </div>
        <div class="right-box">
          <div class="title">{{ item.title }}</div>
          <div class="time-style">
            活动时间：{{ (item.endtime * 1000) | timeFormat("YYYY-MM-DD") }}
          </div>
          <div class="type-style flexc" v-if="item.act_type == 1">问卷活动</div>
          <div class="type-style flexc" v-if="item.act_type == 2">答题活动</div>
          <div class="btn-style">
            <van-button round type="info" color="#999999">已结束</van-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: ["list"],
  data() {
    return {
      current_time: 0,
    };
  },
  methods: {
    /*去参与(热门活动)——未参与*/
    goJoin(item) {
      console.log(item);
      console.log(item.endtime * 1000,"结束时间",   this.current_time, "当前时间戳");
      this.$router.push({ name: "provincialmap", query: { q: item.q } });
    },
    onFinish(item){
      console.log(item,'结束');
      this.$toast('活动已结束了哟！！！')
    }
  },
  mounted() {
    console.log(typeof this.current_time);
    this.current_time = new Date().getTime(); //当前时间戳

    console.log(this.current_time, "newTime");
  },
};
</script>
<style lang="scss" scoped>
.item-box {
  display: flex;
  align-items: center;
  width: 95%;
  line-height: 20px;
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 1);
  margin: 17px 8px;
  padding: 10px 12px;
  box-sizing: border-box;

  .img-box {
    width: 100px;
    height: 93px;
    overflow: hidden;
    flex-shrink: 0;

    /* 隐藏超出容器的部分 */
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      /* 等比例缩放并裁剪，保持图片不变形 */
    }
  }

  .right-box {
    margin-left: 15px;

    .title {
      color: rgba(16, 16, 16, 1);
      font-size: 14px;
      text-align: left;
      font-family: SourceHanSansSC-regular;
      font-weight: bold;
    }

    .type-style {
      width: 54px;
      height: 24px;
      border-radius: 4px;
      background-color: rgba(230, 67, 64, 0.15);
      color: rgba(226, 27, 27, 1);
      font-size: 12px;
      font-family: Microsoft Yahei;
      margin: 7px 0px;
      padding: 2px;
    }

    .time-style {
      color: rgba(153, 153, 153, 1);
      font-size: 12px;
      text-align: left;
      font-family: PingFangSC-regular;
    }

    .btn-style {
      margin-left: 100px;
      .van-button {
        width: 80px;
        height: 30px;
        border-radius: 42px;
        background-color: rgba(255, 163, 43, 1);
        color: rgba(255, 255, 255, 1);
        font-size: 12px;
        text-align: center;
        font-family: Microsoft Yahei;
        border: none;
      }
    }
  }
}
</style>
